//
//  BGMainViewController.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/19.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit

class BGMainViewController: UITabBarController {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置tabBar
        let tabBar = BGTabBar()
        tabBar.bgDelegate = self
        //因为是只读属性,所以通过KVC赋值
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(home, title: "首页", imageName: "tabbar_home")
        addChildViewController(discover, title: "发现", imageName: "tabbar_discover")
        addChildViewController(message, title: "消息", imageName: "tabbar_message_center")
        addChildViewController(profile, title: "我", imageName: "tabbar_profile")
        
    }
    
    //重载addChileViewController方法
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        self.addChildViewController(UINavigationController(rootViewController: childController))
        
    }
    
    //MARK: - 懒加载
    lazy var home: BGHomeViewController = BGHomeViewController()
    lazy var discover: BGDiscoverViewController = BGDiscoverViewController()
    lazy var message: BGMessageViewController = BGMessageViewController()
    lazy var profile: BGProfileViewController = BGProfileViewController()
    
}

//MARK: - 代理方法
extension BGMainViewController: BGTabBarDelegate {
    
    func composeButtonClick() {
        let composeView = BGComposeView()
        composeView.composeViewShow(self)
    }
}
